#!/usr/bin/env/python3.7
# -*- coding: utf-8 -*-

"""
@File    : read_arduino.py
@Time    : 12/07/2021
@Author  : Silence
@Version : 1.0
@Contact : silence2021silence@163.com
@License : (C)Copyright 2021-2021, Silence
@Desc    : None
"""

import serial
import time

class ReadArduino():
    def read_arduino():
        Port = '/dev/ttyACM0'
        baudRate = 9600
        ser = serial.Serial(Port, baudRate, timeout=1)

        t = True
        while t:
            send = '1'
            ser.write(send.encode())
            data_1 = ser.readline().decode()
            print(data_1)
            if data_1 !='':
                data_2=eval(data_1)
                infrared_value = data_2["infrared_value"]
                temperature_value = data_2["temperature_value"]
                weight_value = data_2["weight_value"]
                volume_value = data_2["volume_value"]
                smoke_ttl = data_2["smoke_ttl"]
                smoke_value = data_2["smoke_value"]
                ser.close()
                t = False
        return (infrared_value, temperature_value, weight_value, volume_value, smoke_ttl, smoke_value)

if __name__ == '__main__':
    ReadArduino.read_arduino()